How can I change what URL the ASP.NET SPA Proxy directs to once the proxy is online? - asp.net

In Visual Studio 2022, in the Debug Options there is a way to change the URL that initially loads when you Debug a web application.
However, when using SPA in .net 6.0, the page that initially loads must be the base page, which waits for the SPA Proxy to be online, and then redirects to the SPA Proxy port to load your app when the proxy is ready.
What I'm wondering is if there's any way to set which page this will redirect to, similar to how before using a SPA proxy I could set the debug launch URL to be different from the base / page.
The bundler I am using is Vite, and I have tried using the vite server "open" option to select a URL to open when the server launches. Unfortunately since this is separate from asp.net's proxy logic, they both open. The whole point is I'm trying to avoid loading the base / page.
I have tried modifying the .csproj file so that the SpaProxyServerUrl doesn't just have a port but has a full url, aka from <SpaProxyServerUrl>https://localhost:44466</SpaProxyServerUrl> to <SpaProxyServerUrl>https://localhost:44466/Developer</SpaProxyServerUrl>, but when I do this the spa proxy doesn't launch at all, and the index.html file doesn't load (which is configured in Program.cs with app.MapFallbackToFile("index.html");
Is there a setting I'm missing somewhere? Or does anyone have any ideas on how I can accomplish this? Thank you.

In case anyone else is having the same problem in the future, I was able to get it to work. Strangely for some reason the spa proxy wouldn't let me load my base page (localhost:44366) and load the spa proxy and redirect to localhost:44466/Developer.
However, it worked when both sides were configured to use the same endpoint.
So I changed the debug launch settings to load localhost:44366/Developer and also changed the .csproj's SpaProxyServerUrl to localhost:44466/Developer and then it worked.
No clue why it's setup this way but this change worked for me with .net 6

Related

Blank ASP.NET Webpage for the application deployed on IIS

I have an asp.net application deployed on IIS Server located at 10.0.0.74, when
i tried to access it with chrome browser i get an empty or blank webpage.
However if my colleague tries to access it from his computer he get normal webpage with content on it.
It seems really weird to me what might be the problem.
The screen shot below is what the page looks like.
I would appreciate any help
This is not enough to go on, assuming ASP MVC 5 on IIS here are some suggestions.
On your server
Check the following
Is the physical path in IIS correct - actually point to your code?
Do you have any rewrite rules in your web.config that could be redirecting?
Did you set up the bindings correctly?
Are you hitting the site under https / http?
Checked "Turn windows features on/off" and see if ASP.NET 4.8 installed
Did you setup the HTTP Redirection and HTTP Errors
See how you are setting up error handling setup in your global.asax, see here and disable it
Goto your Control panel > Programs and features > Turn Windows features on or off and under "World Wide Web Services" / components:
Common HTTP features:
Default document
Directory browsing
HTTP Errors
HTTP Redirection
Static Content
Security
Basic authentication
Request filtering
URL Authorization
Windows authentication
The problem was that the plugins in "Content" folder were not included in the projects.
I included all the files shown in the image below.
I apologize for wasting your time, i should have checked the console before!

ASP.NET WEB API 2 Works Locally But Not On Production Web Server

I've developed a new WEB API 2 that works great locally, however when I upload the same code to my production server (Arvixe in this case) all I get is a 404 when I call it. I've spent HOURS searching the web, reading forums, etc.. and have been able to find no resolution, so I'm asking here as my last effort.
I'm currently only testing with the default project that gets created when you do New Project > ASP.NET Web API 2 Empty Project in Visual Studio. This creates an empty project with a single ValuesController. You should be able the JSON response by called /api/values, but this doesn't even work.
I'm using Fiddler to test the API locally and on the web server.
http://localhost:1993/api/values <--- works great
but
http://api.mydomain.com/api/values <--- returns 404
Note: I created a subdomain "api" in this case, but everything for the code for the API is unchanged from when it was created.
Why in the world does this work locally but not on the production web server?
That the server returns 404 (Not Found) may indicate a lot of things. However you can check using the following step:
Add a simple text document like readme.txt to your a folder sub-domain http://api.mydomain.com, and try to get access to that. If you can't access to that file, it means that the subdomain is not configured properly.
Publish the webservice using the "Publish" functionality, so that all DLLs will be copied.
After that,try to reach the Web ApI again.
Hope that help.
"Note: I created a subdomain 'api' in this case, but everything for the code for the API is unchanged from when it was created."
Above comment of your's is suspicious, you should publish your WEB API application in the root directory. Like if http://example.com is pointing to "MyExample" folder, then application should be published on "MyExample" folder.
After that you will be able access your api with http://example.com/api/{controller}/{action}
Just a simple suggestion which I'm sure you have already considered, but have you opened the http port 80 on the server's firewall?
Also stick a plain old html file in the root of your project and see if the server serves it up.
in your case, since you create a subdomain of 'api', you should try
http://api.mydomain.com/api/api/values
note that if you're using database for the function, you should change the connectionString in your web config
Please verify the .net framework on you hosted domain that may be old one.
Web api 2 is supposed on 4.5 framework.
One reason for web api 2 method working OK on local machine but not on production server is that the method you are calling is working on local machine but not on remote server. In such a case you will receive message 404 or 500, and you would be lost why this routing is failing.
Why a method would fail on remote server, well there may be many reasons. For me, I was querying database in my method and my connectionString was not set for remote server.
One way of resolving it would be to put some very simple code in that particular method and test that routing is working. Then check your original code for errors reasons.

Access Control Allow Origin issue and 405 method not allowed with asp.net mvc web api and Sencha Touch

OK, co I have searched and tried what I think is everything. Basically I have an app I have built in Sencha Architect that uses a JSON proxy to call a Get method in my Web API. Running local host, not a problem, deploy to live, not a problem. Run localhost against live web api.. PROBLEM! :)
So, have spent the last couple of hours reading up on CORS and implementing Access Allow Origin in response header, even allowing "OPTIONS" in response header as part of the "pre-flight" check before trying to make the call and still no go. I have set request headers just in case in my call, but convinced this is not the actual issue. I get a 405 method not allowed, no matter what I do.
The crazy thing is, I just wanted to bundle this up as a native app and see if it worked... How does anyone else make a call to a public service using ASP.Net and IIS7.5 +?
Move your sencha app folder in asp.net project folder and run sencha app using IIS server

ASP.NET development server cannot find localhost ?

I have a web site opened in VS 2008 . I try to run it from VS2008 and the asp.net development server starts up.But the browser returns the following error
Firefox can't find the server at www.localhost.
The web address in browser is http://localhost:2921/WebSite2/Default2.aspx
There is no such thing as www.localhost, and nothing built-in to asp.net will redirect you automatically (unless you tell it to). Sounds like you have code that looks at the url and redirects to a www version if you're not there. You shouldn't do that, and instead use relative urls internally that work no matter which way a user hits a page.
Check following :
Are your proxy settings correct in your Firefox browser. Firefox->Tools->Options->Network->Settings.
Are you browsing the correct address, everytime you run/debug your website a dynamic port is assigned unless explicitly specified.

Move from Dev Server to Prod Server - The incoming request does not match any route

I have developed an app on a dev machine using ASP.Net MVC and all is fine and it works. I have moved it to the Prod Server and when I type http://mydomain.com I get the error:
The incoming request does not match any route
If I then make a request to http://mydomain.com/pagename I then get a IIS 7 404 page.
It is hosted in a Full Trust Mode and Integrated Pipeline according to Softsys hosting who its hosted with.
I am currently accessing the site via a temporary DNS name eg/http://mydomain.com.serv7.temphostspace.com and my host believes this might be it.
From the support ticket this is what they say *"I believe, this is caused since you are access your website through temporary URL http://mdomain.com.serv7.temphostspace.com/ and relevant setting might be missing in your configuration."
Any ideas?
Thanks
Your host is probably barking up the wrong tree, unless the site isn't configured. I'd try and request a static file you know is there to be certain. As for the problem at hand, how are you wiring up the routes? Could something in production be failing before this and prevent this from happening?
Anyhow, first place I would start is by using the ASP.NET Routing Debugger to see what routes your app thinks it has.
Similar problem: ASP.NET MVC running IIS7 deployment problem
Resolution from there: http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx
Turns out it was trust issues not configured right

Resources