ASP.NET Page naming using master pages - asp.net

I have two user types: Readers and Authors. And I'm using Reader.Master and Author.Master for authorization purposes.
Then, there are StoriesR.aspx inherited from Reader.Master and StoriesA.aspx inherited from Author.Master. (In StoriesR.aspx page, you able to read the stories and in StoriesA.aspx you able to write the story.) So,
Reader.Master --> StoriesR.aspx
Author.Master --> StoriesA.aspx
Now, the thing is I don't want my users to see StoriesR.aspx?s=3 or StoriesA.aspx?s=3 in their browsers. I only want them to see stories?s=3. (even without the .aspx part)
How can I achieve this?

you can do this using urlMappings from web.config file
add in web.confing
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<urlMappings enabled="true">
<add url="~/reader/stories" mappedUrl="~/reader/StoriesR.aspx"/>
<add url="~/author/stories" mappedUrl="~/author/StoriesA.aspx"/>
This will do url mapping.

You could have one aspx page and change the master page programmatically depending on what type of user they are, Author or Reader.
You can do this in the Page_PreInit event of your aspx page.
Check this c# example or this VB example

Related

Setting static variable in compiled ASP.NET

I have compiled ASP.NET dynamic page with editable aspx pages.
I would like to some links to be generated upon changing some static variable
What i did is edit:
web.config as follows:
<appSettings>
<add key="currentEnvironment" value="dev-"/>
</appSettings>
and then
edited aspx page as follows
Home
But there is nothing appened when i try and run the .aspx page. Please help
You can't put a server tag inside another tag's markup like that, but you can just use the value directly. If you remove it and change the # to a =, it will work.
Home
Although if you can access the code behind, that would be a much cleaner way to do it, as in:
<asp:HyperLink ID="_index" runat="server">Home</asp:HyperLink>
and then set value from code behind
_index.NavigateUrl = String.Format("http://{0}www.mysite.com/web/index.html", ConfigurationSettings.AppSettings["currentEnvironment"]);

How to work with update panel, if the page abc.aspx contains usercontrols?

I have a web page abc.aspx using this page like master page, in this page i wrote a Html tag iframe using this i frame as content place holder.
I'm calling home.aspx page in this iframe tag.
in my home.aspx page i have some user-control. So , My question is
how can i able to implement the update panel in this scenario please tell me the solution.
Thank You,
Gorus.
After commenting the xhtmlConformance tag in web.config, update panel working normally.
<system.web>
<xhtmlConformance mode="Legacy" />
</system.web>
please refer below link....
http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx

ASP.NET error: The page Y.ascx cannot use the user control X.ascx

I am getting the error below when trying to build the web site project in Visual Studio 2010:
The page '/WebSite/controls/C2.ascx' cannot use the user control '/WebSite/controls/C1.ascx', because it is registered in web.config and lives in the same directory as the page.
I have 2 web user controls:
controls/C1.ascx
controls/C2.ascx
The controls have been registered in web.config:
<configuration>
<system.web>
<pages>
<controls>
<add src="~/controls/C1.ascx" tagPrefix="my" tagName="C1"/>
<add src="~/controls/C2.ascx" tagPrefix="my" tagName="C2"/>
</controls>
</pages>
</system.web>
</configuration>
C1.ascx contains just a static HTML, C2.ascx is trying to include C1:
C1.ascx contains just some plain static simple HTML. C2.ascx is trying to include C1.ascx:
<%# Control Language="VB" %>
<my:C1 runat="server" />
<p>Hello from C2</p>
When trying to build the project, I am getting the error message at the top. I realise this issue can be fixed by adding another Register directive to C2.ascx...:
<%# Register Src="~/controls/C1.ascx" TagPrefix="ctl" TagName="C1" %>
...but I'm wondering if there's a cleaner solution and why am I getting the error in the first place?
Your only possible solutions are to:
Move the control out of the directory its currently sharing with outer.ascx, or
Re-register the control inside of the outer.ascx like you already mentioned
Re-write them in code as controls in a separate library
I personally think moving is the easiest, if it will work for your solutions. Second would be re-registering, even though annoying. Abstracting them out into a full code library is probably not worth the effort if this is the only reason you are doing it.
You could also put the controls into different folders. But I don't think this is much cleaner or better.
BTW: this behavior is by design, as you can read on this MSDN page (look for the yellow note almost at the end of the page).

Do you disable viewstate by default when developing asp.net webform?

we know that view state is easily get abused, but asp.net webform are heavily depending on this feature.
I want to know whether you disable viewstate by default, and ONLY add it wehn it's needed. Or you take the visual studio default, which actually enables viewstate by default.
I tend to take the default of having it on when doing web.forms.
But when writing my own user controls I disable it until I need it, or I find something doesn't work. I also monitor the size of the view state and when/if it gets too big I look at what the page is doing and change what I'm doing on the page. I.e. bind to data objects containing only the data that is needed and no more... stuff like that.
As others have said, unless we are talking about a fairly static page, I tend to leave the ViewState on while developing, and begin selectively disabling it when the page works. That way, it's one less thing to worry about upfront.
You may find this interesting, in ASP.NET 4.0, we will have more efficient control over disabling the ViewState: http://www.asp.net/learn/whitepapers/aspnet40/#_Toc223325478
Personnaly, no. Eventually, to have it disabled will be the behaviour that you will want but most of the time, no. Also, I would do a manual ViewState optimization pass and disabled controls' ViewState that wouldn't need it if really necessary. It's better not to have the ViewState to worry about while you are in heavy development imo. I'm not saying here that you shouldn't care about the ViewState at all but to put EnableViewState aside until you feel the need to lighten the trips to the server.
Turn off the ViewState by default by using a <page> element in the web.config. Using EnableViewState="true" in the #Page directive will no longer work once you disable the ViewState in the web.config. If you decide later that you need the ViewState for a specific page, you can turn it back on for just that page using a <location> element.
<configuration>
<system.web>
<pages enableViewState="false" />
</system.web>
<location path="MyFolder/MyPage.aspx">
<system.web>
<pages enableViewState="true" />
</system.web>
</location>
<location path="Site.master">
<system.web>
<pages enableViewState="true" />
</system.web>
</location>
</configuration>
You need to do the same for any master pages that your ViewState enabled page uses.
I go one step further, I've created a class that inherits from the Page class and override 2 functions
protected override void SavePageStateToPersistenceMedium(object viewState)
{
}
protected override object LoadPageStateFromPersistenceMedium()
{
return null;
}
Then have my page that requires the viewstate to be disabled inherit from this.
Works very well.

HTML in an ASP.NET Dynamic Data MultilineText Control

I'm trying to enter a little bit of HTML into an ASP.NET Dynamic Data MultilineText_Edit control, just a couple of <br> tags to have line breaks when I output the value of the column on a web page.
However, when I try to click the "Update" link on the Dynamic Data edit page, nothing happens. I don't even get an error message, which I would expect if HTML input were not allowed via some rule the control has built in. As soon as I remove the tag, the update link works correctly. It's not a column size issue, I can add a bunch more characters to the input and everything works fine.
Is HTML input not allowed in these controls, or is there something else going on? If there is some kind of validation rule, can it be turned off? Or is there something in the database that I need to set? Should I use something other than the default multiline text template?
Input validation is a built in feature in ASP.NET 2.0 or later. I don't know why you are not getting an error, but check this out to see if it helps:
http://www.asp.net/learn/whitepapers/request-validation/
Check these settings, on the page:
<%# Page validateRequest="false" %>
or the web.config:
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
</configuration>

Resources