Blazor page to MVC page - c#

I try to logout in code in a procedure on a Blazorpage.
var url = $"{navigationManager.BaseUri}Identity/Account/Logout";
navigationManager.NavigateTo(url);
That doesn't work. I got the message
Sorry, there's nothing at this address.
Odd, because the address directly in the addressbar of the browser, brings me to the logout page.
What do I miss that blazor does not seem to find the logout

Force a reload with the second parameter your not using.
navigationManager.NavigateTo(url,true);

Related

Getting 302 response code in widget ajax call

I am working on a MVC application in which when have an option to request password reset email. When we got the email with the link, that link will redirect to the welcome page where we will enter Password and Confirm password and then we will click continue. Once all the validations of Welcome page passed, the user will be redirected to Dashboard page where we are loading few widgets through ajax calls. In one of our production environment these ajax calls are giving 302 http code instead of 200. Due to this behavior the widgets are loading either welcome page or login page as their content instead of original content. From the code base, no where we are redirecting to Welcome page or login page from any of the widget ajax calls. As this is happening in only production environment but not in local, it became hard to debug.
Can anyone please help guide me on how to figure out the cause of redirection.
Thanks....

Sharepoint 2013 welcome page redirection issue

I am facing a weird issue where I have changed the welcome page of my sharepoint 2013 site to a page called Home.aspx, so now my welcome page link looks like https://abc.sharepoint.com/sites/ThisIsSCName/Home.aspx. When I share the link of the site, to my team as https://abc.sharepoint.com/sites/ThisIsSCName, most of the time it works fine and redirects to Home.aspx, but sometimes it's redirecting to default.aspx, for example, like once or twice in ten times when I load the site, it's redirecting to default.aspx. It's so strange. I tried hard to crack the error, but could not. Help me in this issue!!
Not sure why this is happening. Is it happening to a certain set of users or everyone?
but as a workaround, you can redirect from default.aspx to home page by placing a redirect script in content editor webpart on default page.
function Redirect() {
window.location="http://yourpage.aspx";
}
This will appear as if its redirecting to home everytime.

Asp.net Url loses page path on postback

Background:
We are redoing our website and trying to modernize it. We were initially experimenting with AngularJS but dropped it due to some of our users being on unsupported browsers. We ended up just doing VB webforms and updating the design and functionality of our site.
I was having an issue with buttons or items that cause a postback. When the page tries to postback it hits to the path but loses everything between the hostname and the last "/"
For example I have a login page set up in the location
/Secure/Account/Login.aspx
I have a route as well that directs from /Secure/Account/Login.
So when you visit the page you are at:
www.website.com/Secure/Accounts/Login
When I click the login button though, instead of posting back, I am directed to:
www.website.com/Login which doesn't exist so I get an error.
This occurs if I navigate to the page instead of using the route as well. So if I am at www.website.com/Secure/Accounts/Login.aspx and click the button, I end up on www.website.com/Login.aspx with an error.
This doesn't affect pages in the root directory as long as they do not use routing attributes. We have some pages that use routing attributes that have the same issue though.
We have page /Category.aspx in the root directory with the route
/Category/{Attribute1}/{Attribute2}/ configured for the page.
If I am on the page www.website.com/Category/Attribute1/Attribute2 when I click on a button that posts back, I end up at www.website.com/Attribute2 with an error.
The issue ended up being a really small piece of code from when we were working with Angular
On our master page .aspx we had included the line:
<base href="/">
Removing this line, which we didn't even need anymore fixed the issue.

Redirect to Browsers Homepage

I am working on an asp.NET 4.0 Web Application, using C#. I would like to redirect the user to the homepage of his browser. Is this possible?
This will be done because internally we are using an intranet, and we would like to make it redirect to that intranet without having to hard code it and since the homepage is by default the url of the intranet, it would be better if we could use the homepage instead of hardcoding it.
EDIT:
We are using IE here, and will not change most probably as that is the standard. So as long as it works with all IE Versions, it's fine.
Use Javascript to return to the user's home page,
e.g.
function goHome(){
if (window.home) {
window.home();
} else {
window.location = "about:home";
}
}
and then call the JS goHome() function somewhere on the page (or even on a hyperlink).
As stated above, use the about:home uri.
Another solution would be to store the intranet url in the web.config and use this value. Then if it ever changes you will only need to change it in one place.
As far as i know it is not possible (been researched alot). But if all homepages are the same why not simply use META REFRESH?
EDIT
Try linking to this: About:home
Go home!
worked for me in IE9
EDIT 2:
Sending user to their browser's Home Page using Javascript
This will get you started for firefox and safari
EDIT 3:
Response.Redirect("about:home", false);
You cannot redirect server side to a users homepage.
SERVER <> USER (server is not the user)
Therefore the server cannot know what the user's homepage is.
So if you you use some sort of javascript redirect, then you sort of can redirect to home, but its a little glitchy.
All in all there is no cross-browser way to redirect to a user's homepage.
You Can't!
You can't retrieve the user home page because of Security and Privacy issues, and there is no Cross-browser work around.
What you can?
You can redirect to any page, so you can simply redirect to your intranet home page.
its also more future proof so that if your intranet homepage changes you just have change to redirect to the new address instead of changing every single machines home page.

How do I redirect to a page after successful login?

I'm fairly new to web forms development, playing around with a project created using the ASP.NET Web Application template in VS 2010. After the user successfully logs in, I want the user redirected to a page I created. How do I modify my project to redirect the user after login? Any samples / tutorials / etc are greatly appreciated.
Thanks!
To simply redirect to a new page when your user has logged in, use the DestinationPageUrl property of your login control... assuming you're using the Login control that is.
If you need to do anything more advanced you can use the OnLoggedIn event handler for your Login control to perform a redirect manually, or add any code for event logging and such.
If you've rolled your own login control, and are just using things like text boxes and button controls, then in your Button_Click event, you can just use Response.Redirect("DestinationHere"); to take your users to a new page.
After you checked for login:
Response.Redirect("url");
I assume you're using ASP.NET Login control. There's a DestinationPageUrl property of that control that handles exactly that. If login was successfull user is redirected to URL provided in that property.
<asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Admin/Default.aspx">
</asp:Login>
Go to Properties and Set DestinationPageUrl.
Server.Transfer( *url*) ?
(method on HttpServerUtility)
I know next to nothing about ASP.NET, but from my Java web developer daze, redirect is bad because it involves another network round trip to the browser and back when you really just want to continue processing in another page.
And Response.Redirect() really does issue a 302 response code ("try this other url instead") back to the browser. yuck. XP
Server.Transfer() looks like the java version of Response.Forward()
For Sharepoint farm solution development
Page.Response.Redirect("url");
The issue with Response.Redirect() is the 302. In some browsers (eg Chrome) this causes the new session cookie to be immediately invalidated.
In other words, using that method to redirect causes the user to no longer be logged in, so you did not accomplish your purpose!.

Categories

Resources