I have a Login.aspx page, and I wanna incude some piece of code in that page. I know I can do Response.WriteFile ("HelloMessage.aspx"), but if I simply do Project->New Item->Web Page, the GelloMessage.aspx page will be accesible throught Web browser. I wanna do this HelloMessage.aspx file unaccessible.
How to do this?
And question 2, can I keep aspx files in my custom folders?
Yes, you can keep apsx files in subfolders. Those folders become part of the URL (as long as you don't add routing).
And you can block files using the <authorize> tag in web.config. Which could solve your fist problem (but to who would you allow access to Hello.aspx ?)
Every folder can has its own web.config. So, an easy example:
For all pages in the same folder as this config, deny access to anonymous users and allow access to all logged-in users:
<authorization>
<deny users="?" />
<allow users = "*" />
</authorization>
If you have some markup that you'd like to include in several pages, then you should either use a user control, or perhaps a master page.
Related
I have a Web Forms site in ASP.NET using C#. I have a folder that I like to modify so only certain users can access it. I've already done this through the web.config file of the folder with:
<authorization>
<allow users="User1, User2, User3" />
<deny users="*" />
</authorization>
But I have a string list with all the users that need to be put in the 'allow users' attribute. The string list gets populated by a Table in the database. So I want to use the string list or the database instead of manually writing all the users in 'allow users' attribute. How do I do this? Even if using AppSettings, still don't know how to actually do that.
I would suggest that instead of using the user you instead use Roles. You can add the role to the allow list and give all the users that match the database the required role when logging in using a RoleProvider.
Here is a link to a pretty thorough article on how to achieve this http://www.codeproject.com/Articles/607392/Custom-Role-Providers. It is an MVC example but can also be adapted for web forms, if you are using that. It also shows turning off and on elements based on the roles.
So I found this question:
Is it possible to reference a value from an SQL database in a web.config file?
And I found that you actually can't. Which is weird because I have come across some info that you can with AppSettings, but ok. I managed this without the web.config file, I just redirected the users to the homepage if they weren't in the string list.
I have uploaded my application to live server published code into iis my tab doesn't works on live,tab gets post back on the local, # gets appended automatically at the end of the url unable to postback on the server which causes the postback working to stop.
Look for JavaScript errors on your page. If there are, the tab will not be able to execute its JS logic, so it will act as an ordinary anchor and add the hash to the URL.
It is often the case that webresources do not load on your production server because of permissions. Check these two articles for more info on troubleshooting that:
http://www.telerik.com/help/aspnet-ajax/introduction-troubleshooting.html
http://www.telerik.com/help/aspnet-ajax/introduction-web-resources-troubleshooting.html
You will, most likely, need to let your user access webresource:
<location path="Telerik.Web.UI.WebResource.axd">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Also, you can try using the CDN to avoid loading resources from your server: http://www.telerik.com/help/aspnet-ajax/scriptmanager-cdn-support.html. If you have it enabled already, then you may not have connection to the cloud where the scrips come from, so you can consider disabling it.
On our website we have images dropped on a grid with the following line:
imgUpdated.ImageUrl = "./images/Test_Icon.gif";
This works fine when published to production or test websites but within the IDE it gives broken (Red-X) images. Properties on the broken image says this:
http://localhost:52168/OurApp/images/Test_Icon.gif
If I attempt to past that into a browser, it redirects me to the login page with the following URL:
http://localhost:52168/OurApp/login.aspx?ReturnUrl=%2fITRequest%2fimages%2fTest_Icon.gif
I'd appreciate any help you might offer. I've already tried setting up a virtual directory in IIS and taking out the period but that didn't help.
create a web.config file with the following xml and place it in your images folder
<configuration>
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</configuration>
This is likely the reason your IDE doesn't show the images. If your browser is giving a 401 response and redirecting to your login page, the IDE is expecting an image MINE type.
You can find more information on the authorization section
Your image or any other content paths should start with forward slash / which points always to the root of your website. That way no matter in what environment you are your path will always be the same. So, answering your question... your path should look like this:
imgUpdated.ImageUrl = "/images/Test_Icon.gif";
I have a VS 2008 web application running on IIS 6. In the web.Config wile there is a section like this:
<location path="public">
<system.web>
<authorization>
<allow users="?"/>
<allow users="*"/>
</authorization>
</system.web>
</location>
I have a user control which is used on numerous pages in various locations to provide content. I want that control to filter content based on the location of the page it is on. For example, if the control is on an aspx page located in the "public" folder as specified in the sample above, I would like certain information to not be displayed.
How can I accomplish this in my codebehind? It may also be that this web.Config setting is completely irrelevant, to this question, you decide. VB or C# are fine, I can translate.
Perhaps something like this? If path.Contains("public") Then filterResults()
Thanks! :)
I would add a public property to the user control called "Mode" OR "ContextUrl" or something to that effect. Then branch logic off of that property. You should also have a 'default' set of logic.
Ultimately, having this behavior dictated by a public property is something that is more intuitive and testable to the "developer" who is interacting with your user control as opposed to something hidden in the controls implementation.
I currently cache everything possible on my site (images, JS, CSS). There is only one JS file that I need to be loaded fresh every single time. How do I omit just one file from caching, using web.config, whilst leaving everything else cached?
Note that I tried another link here, and it didn't seem to stop the caching of my file:
How do I disable caching of an individual file in IIS 7 using weserver config settings
How about:
<configuration>
<location path="path/to/the/file.js">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
(Note that the path is relative to the web.config file)
I don't think you can do it using web.config, but you could add a unique querystring parameter to the javascript url in order for it to be loaded every time:
If you are using ASP.NET
<script src="mycode.js?<%=System.Guid.NewGuid.ToString()%>"></script>
Set the path for it not as a static URL but get an ASPX page to serve the script. Inside your ASPX page just send back the text:
byte[] javascriptTextBuffer = GetMyJavascript();
Response.ContentType = "text/javascript";
Response.Write(javascriptTextBuffer);
Inside the page turn off caching.
Having said that, it seems to me that you are doing something wrong that have to load the JavaScript file everytime. Make scripts static but use parameters to drive versatility.