How to rout the URL in asp.net - c#

I have a page in my asp.net application, using this page with an number of links to open it, now I have a new version of same page with different name and extra functionality.
I need both page should be serve by same links depend upon user permission, suppose user "A" have permission to access old version of page then he should get old one and if user "B" has permission to access newer version of page then he should get new page, the page access permission logic will be derived from database.
I have an idea to do it by using a common page that will be linked with every link in application, under that common page I can check which page access current user has and redirect him accordingly, but I do not want to change every link in my application to change the old page link with common page.
I need some concrete functionality of asp.net application like URL routing.
Please help if any one have any Idea on this.

On the Page_Load of your login page, you'll want to check if the user is authenticated, and if they are to redirect them to your access denied page:
protected void Page_Load(object sender, EventArgs e)
{
if(!User.IsInRole("A"))
{
Response.Redirect("~/NewPage.aspx");
}
}

Related

How can I redirect a webpage in C#

I am making a simple website in c#, I have a login system and I want to redirect a user to a new home page once they are logged in, how do I do this?
Also how do I redirect someone to a new page at the click of a button? e.g click btnMath redirects user to MathPage.aspx
Response.Redirect("url");
You can do the above
there are many method available to do so. One of those is response.redirect
Response.Redirect("MathPage.aspx")
Remember to mention path correctly inside response.redirect.
You can read this link as well.

ASP.NET - Who can use one web application and "host" many sites

I've a personal project, and the logic layer and database is equal, but I've two domains that the only thing that changes is the URL, and the master page.
What I need is a simple system to recognize the URL and show the correct site master, because I what use the same database with the configuration of ASP.NET tables, stored procedure and so one.
The most similar thing I've saw, it's the DNN portal system, but I don't need all the features, like separate login system.
Thanks in advance.
I think something along these lines will get you what you need:
In IIS, point both URLs to the same virtual directory, so they are both being served from the same place -
Add a PreInit event to read the URL then load a MasterPage accordingly:
void Page_PreInit(Object sender, EventArgs e)
{
if(Request.Url.AbsoluteUri.Contains("mysite.com"))
{
this.MasterPageFile = "master page file goes here";
}
}
Hope that gets you in the right direction!
You could make the master page dynamic. The host name can be found in:
HttpContext.Current.Request.ServerVariables["SERVER_NAME"]
You can use this inside the master page to change its output.
I would take it one step further and abstracting everything away that differ and then use dependency injection to resolve what you need.

Disable access to pages after logout (Session.Abandon) in C#/ASP.NET

I'm interested in disallowing the following after logout:
-- no back button
-- no direct access to pages via URL - for example: if the user logs out then they should not be allowed to see a cached page using some URL (e.g., replacing the URL with a valid URL in the site http://mysite.com/Gotothispage.aspx)
I've seen similar questions like this one: How to disable the back button in browser when user logout in asp.net c#
I know that I can set no cache on the master page, but then I lose the ability to use the back button when the user is actually logged in. Am I correct in this understanding?
A page is either cacheable or it isn't, the browser has no idea if you are logged in or not. You can't somehow retrospectively expire objects already cached by the browser.
Then I lose the ability to use the
back button when the user is actually
logged in. Am I correct in this
understanding?
Not entirely - you'll have problems using the back button on pages that are submitted using POST, but not GET.
A simple example would be to imagine an ASP.NET page with a paged Gridview - the user clicks pages 1,2,3,4,5, etc to navigate the grid.
Using POST, every time the user clicks another page in the grid, it will cause a postback to the same page. A page expired error will appear if the user clicks back after doing this.
Using GET, every time the user clicks another page in the grid, it will redirect them to the same page using a querystring (ie, Grid.aspx?Page=2). In this case, the user can click back, and it will take them to the previous page without any problems.
Pages should already be disabled after logging out, if your security is setup correctly.
If you have a master page or basepage class specifically for users that are logged in, you should check if they have a sessionId that you set when they logged in.
If they don't, redirect them to another page.
Users may see a cached version of a page, but can't do anything to it.
In my basepage class for members, i check if they are logged in on the OnInit event:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!IsLoggedIn)
{
Response.Redirect("default.aspx");
}
}
Edit:
What some sites do is..after you log the person off, they redirect you to a temporary purgatory page that says it is logging you off. This purgatory page will have caching turned off, and has a meta-refresh tag that takes you to your destination page.
So when the user clicks on the back button, it takes them to the purgatory page which then directs them right back to where they were.
Gmail does this, but sometimes it's so fast you can't tell.

Asp.Net page reload problem after login

I am devolping a web application.the problem is that i am using a login control (not a .NET control) which is a part of master page and is acessible from all pages. if user log In from a page the login control updates itself and displlay some statistics of logged In user but the specific page does not reload. (some options on page are visible only to authenticated users, so that after login, page should be reloaded to display such options)
after logIn methoed I wrote
Reponse.Redirect(Request.Url.AbsoluteUri)
after this the browser response the "Page cannot be displayed"
It would be of great help to me.
Many Thanks, Regards. AZHAR
From you description it is not clear what happens, but with high possibility you get infinite loop, when page is redirected to itself again and again.
Most obvious problem that you place redirect code in Page_Load,
as possible resolution:
Place Reponse.Redirect(Request.Url.AbsoluteUri) to OnLogin event of your login control
if you anyway want use Page_Load, at least add following check:
if(IsPostBack)
Reponse.Redirect(Request.Url.AbsoluteUri)
But last case is very bad style because may have lot of side effects.
Make sure your redirect is not causing a loop. Check Page.IsPostBack
Be aware that POST variables are lost during this operation.
Another thing that you should look at is the roles that you allow in the folder (in the web.config file in the folder).
I accidentally misspelt a role name and it kept redirecting my users to the login page.

Facebook App Profile Tab is Empty ... No Content Displayed?

I can view my application via the http://apps.facebook.com/myapplication/ link and the content shows up correctly. I also added the application as a tab to a facebook page. However, when viewing the tab no content is displayed.
I am using version 3 of the facebook toolkit for asp.net.
From what I've read this is caused by a redirect being caused to login. I used:
protected void Page_PreInit(object sender, EventArgs e)
{
base.RequireLogin = false;
But that doesn't fix the issue.
For debugging, I added a line to write to log file in the Page_Load and Page_PreInit. When viewing the app at http://apps.facebook.com/my_application/thepage.aspx a test string is written to the log at both Page_Load and Page_PreInit.
But when loading that same page (as a tab in a facebook page) nothing is written to the log file; as if Page_Load and Page_PreInit isn't being hit.
Does anyone know what is going on?
Turns out facebook wants a / at the end of the canvas URL. Otherwise the relative links wont't work.
My understanding is that Tab Pages for a Facebook Page only supports FBML applications not iframe.
Is your application iframe?

Categories

Resources