So this is going to bed a dumb question because I understand there is a simple solution, I just cannot figure it out....
At the moment I am running my MVC 5 project in visual studio 2013... Normally when I want to debug it I will just click run and the website will appear in the browser of my choice...
I just recently published it to my companys web server and now I am having all kinds of issues...
The website is just 15 buttons on the Home/Index page and I want to be able to click on the buttons and still run them on my localhost side and when I publish them, still have them find the right path..
Here is an example because I am not very good at explaining things...
I run it in visual studio my url is:
http://localhost:54641/Home/Index
I run my published site on the webserver my url is:
http://webserver/racklabels/dakkota/Home/Index
I understand this part, and in either case both of them work but when it comes to clicking on a button, or images.. the pathing is all weird and I dont understand it.
In visual studio I click my first button and my url becomes:
http://localhost:54641/RecieveTruck/AddFor
On my webserver I click it and it turns to:
http://webserver/RecieveTruck/AddFor
but gives me the 404 error because it is not the correct route ( which should be..
http://webserver/racklabels/dakkota/RecieveTruck/AddFor
)
This is how I have my button setup in my View (Index.cshtml) and I am wondering if this is what is causing the probelm (I am thinking that I may have to do it a different way other than using onclick)
<input type="button" name="receive" value="Receive Truck" style="cursor: pointer;" class="bodyText"
onmouseover="this.style.color='orangered';" onmouseout="this.style.color='black';"
onclick="document.location.href='/RecieveTruck/AddForm';">
Basically I would like for this to work regardless of how many folders I am deep after I publish it and when I click run in visual studio (so I can debug/test and just republish to the webserver when I want to update)
I have tried many different ways of sending the path... like '~/RecieveTruck/AddForm' (which just adds the ~ to the address) and '../RecieveTruck/AddForm' and just 'RecieveTruck/AddForm' but none of them find the actual root of where the project lives and just adds this to it...
Can anybody help me?
You can use
#Url.Content("~/Home/Index")
but this completely misses out the benefit of mvc routing.
if you want to generate urls for controller actions, it's much better to use
#Url.Action("Index","Home")
...so now if you set up some snappy routing rule, the url in provided by .Action will adjust automagically (such as omitting url parts that have default values in your routing rules).
You need to add "~" to the front of the url document.location.href='~/RecieveTruck/AddForm'
or if that does not work use document.location.href='#Url.Content("~/RecieveTruck/AddForm")'
Related
I've been working for weeks building/debugging a critical part of the site. Lets say I want to navigate directly to here:
~/Critical/Create/100
This "edits" record 100.
The cshtml file that runs this is called Create.cshtml. I did notice if I have it focused in the IDE that I will go directly to ~/Critical/Create
This isn't good enough, because /Create will go to the blank record creation screen.
Is there some setting somewhere that I can set that will force the debug session to go directly to some url, no matter which .cshtml file is focused? Ideally, then I could go to ~/Critical/Create/Random and load a random record.
This would save me about 5-10 seconds clicking my way there.
Thank you.
Right click properties on your MVC project .csproj.
Edit the Web / Start Action to have the specific page. The value you want here is the URL route that you want to load. I'm not sure if this is your actual route, but whatever the URL is, put that here. No leading / character.
Be sure there's no other value in any other box in the Start Action section.
I have been some time using asp.net charts, even it was hard to config for asp 3.5 and to make it work, I have been able to move along with all my project but I'm facing something that I have no idea how to solve.
This project works perfectly on my develop enviroment, but when i deployed it on the server, the only page with charts on it appeared like this:
I assume its cause of the charts because its the only thing that really have given me problems and its the only thing that its exclusively on this page but i have no idea how this happens, it only happens on the server with Plesk.
Tried to upload on debug instead of release but the result is the same. Searched overall but never found anything like this.
My Answer may not give you the exact solution. But it may give you an idea's.
Below are my Ideas:
Make Sure you have included all the files into your solution when you do the Build.
Make Sure you have all dependency of Asp.Net Charts in Server.
Check you browser Console and Browser Network. Press F12 in your and check. You can get to know the Exact problem if any issue in loading prob / dependency files.
Double check your server configurations for the charts. And compare your local and server configs.
Do the Deployment in your machine itself and check one round.
I am occasionally getting "Application compilation is starting." event in my Event Log and I can't identify what's causing it. I think I may try this - http://blogs.msdn.com/b/tess/archive/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing.aspx - but before I do that I was curious if I can identify the problem without starting to mess with something unknown.
I have used <%= %> and <%# %> tags throughout the app so I am wondering if this is what's causing the problems. On couple spots I have embedded C# code (using ) so that may add to it?
Precompiling the app is also valid choice for me, I just don't want to end in position in which I need execute precompilation command on the server every time I upload some changes to the server. Currently on my dev machine I've followed advices from this link - http://mikehadlow.blogspot.com/2008/05/compiling-aspx-templates-using.html - and it does awesome job as it allows me to identify errors in C# code in .aspx pages during build in Visual Studio. However, I presume precompilation results are not stored in my website directory (and won't be published when I use Publish option).
Ideally, I want to stay in position I am with default Web Application model with addition of automatically running compilation as soon as I upload changed .aspx or .ascx over FTP (not waiting for user's http request). Am I asking too much, or is this possible to setup?
From my research it seems it can.
Because nobody responded I'll accept this as answer.
Sorry if this is duplicate but I've been going crazy for the past two hours over this.
After changing the Master Page in ASP.NET MVC 1.0 application, I keep getting this familiar error when I try a postback without filling in the mandatory form elements which are validated by the server:
"Validation of viewstate MAC failed.
If this application is hosted by a Web
Farm or cluster, ensure that
configuration specifies
the same validationKey and validation
algorithm. AutoGenerate cannot be used
in a cluster."
The new page refers to a lot of jQuery code with lightboxes, superfish etc. Could that be a problem while doing a postback?
If I revert back to the original master, the error disappears and I'm able to validate form fields. Both masters are located in the same path.
I know a lot of other guys have faced this issue but I was unable to find anything which could help me.
Thanks.
Edited and added
After a little debugging, I've realized that a directive in the master page:
<% Html.RenderAction("menu", "nav"); %>
is creating the problem. The directive asks the "menu" action of the controller "nav" to inject a partial view Menu.ascx. If I delete this line from the new master page, everything works OK. My app's left bar navigation relies on this directive to work properly. Is there any way I can get around this? Very mysterious.
Are you using Html.AntiForgeryToken() anywhere on this page? Sometimes when I am testing locally with multiple different sites and / or port changes this will happen to me. If it does I clear my browser cache and it works just fine.
I did experienced the same problem two days ago. :)
A simple restart of the box has worked in my case so I did'nt investigate further.
I have
an ashx file,
Visual Studio 10,
no knowledge at all about C# ASP.NET
What is the proper way to compile and run this?
Context
The ashx file in question can be found in this zip, and is a demo application for a Tetris AI competition. It is a very enticing idea even if it depends a great deal on luck, and I thought I might use the occasion to learn a new language.
An ashx file is a just a generic HTTP handler, so the easiest way to get this working is to create a new Web Site in the File menu, and just add the Handler.ashx file to the website root directory.
Then, just run the site (F5) and browse to "YourSite/Handler.ashx".
An ASHX file is like an ASPX file, but it's a handler. That means it doesn't respond back with HTML by default, and can therefore "handle" otherwise unhandled file types, but it's not necessarily tied to that meaning. In this case, you'll only be presenting the response
position=8°rees=180
...to a posted board and piece. So you don't need HTML, so you want an ASHX.
You can make .ashx files the startup page in your project, just the same as .aspx pages. If I were writing a HelloUser.ashx page, I might set it as the start page, with some parameters passed in as querystrings or something.
You're probably going to want a test harness that posts a board / piece to your service, and that could be any kind of project. Command line program, website, test class run through NUnit, whatever. There's a lot of logic to keep track of beyond the "player" logic.
If you need a more detailed answer than that, SO might not be the place for this question. But I wish you all kinds of luck with this - it's an interesting problem.
You need to deploy it to an IIS server that has the proper .NET framework installed and that should be it.
If you are trying to get it working locally, create a web site project in visual studio, go to "add existing items" in solution explorer, and locate your ashx. Then click the play button (or press F5) to compile and run it.
Good luck!
You're missing an some form (an ASPX file maybe) that goes with this handler. It looks like this thing probably handles some AJAX request from another page.
It's expecting 2 pieces of data with the request as well:
string board = context.Request.Form["board"];
string piece = context.Request["piece"];
You could reverse engineer the form that this is for, but it will probably take some time to get that board array right.