asp.net-mvc

How can I upload a file and save it to a Stream for further preview using C# ?

Hi!! Is there a way to upload a file, save it to a Stream, this Stream I will save it temporarily in a Session and, at last, I will try to preview this uploaded file that is in this Session?? For example, a pdf file. Thanks!! EDITED Here's what I'm trying to do: HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; byte[...

ASP.NET MVC - Shortening urls

I am developing an international web site - multiple countries, multiple languages. I am trying to create SEO friendly URLs. For example the catalog consists of cartesian product Regions x Categories. A typical catalog url has 7 levels of hierarchy: www.site.com/en/Catalog/Browse/10/28/London/Category1 The route format is as follows: ...

How to unit test ModelBind with Data Annotation validation ?

I am working on asp.net mvc application using the mvc2 framework. Here is the view. <% using (Ajax.BeginForm("CreateMenuCategory", "Admin", new AjaxOptions { UpdateTargetId = "tabs-MenuCategories", })) { %> <fieldset class="fields"> <legend> Add Menu Categories ...

Simple upload/download form in ASP.NET MVC

I'm getting started with ASP.NET MVC, but would like to explore further. I've walked through the usual "hello, world" examples, and now I'd like to try something a little more complex. Specifically, I want to be able to: upload some XML file, do some simple processing on it, and then allow the user to download a new file with the resul...

RequireSSL fails on Url with Querystring

I use this code which is taken from MVC futures and attach the Attribute RequireSsl to an action. It works with simple Url like http://localhost/de/Account/Login, but if I have a querystring, the questionmark gets url encoded and the request fails. http://localhost/de/Account/Login?test=omg redirects to https://localhost/de/Account/Log...

What is the best way to customize user authorization when basing user privilege on something other than specific accounts/roles?

I'm trying to write an ASP.NET MVC application where user privilege is based upon points rather than by a hard-coded role per se. I've tried researching authorization and membership providers but all the information I find points back to role based authentication which isn't really part of my model. While writing this question I'm wond...

dynamic linq Like

How to write a dynamic linq method for Like clause. For.: the reference for Dynamic linq orderby is http://stackoverflow.com/questions/41244/dynamic-linq-orderby. I am looking for a similar one for dynamic Like clause. I have the following extension methods for like: public static IQueryable<T> Like<T>(this IQueryable<T> source, str...

assign nullable objects for returning IQueryable

I am returning IQueryable<Customer> to the other method for some querying operations. The return method looks like: return from cust in _dbCustList select new Customer { CustomerId = cust.Customer_Id, FirstName= cust.First_Name, LastName= cust.Last_Na...

In C#, how can I know the file type from a byte[]?

Hi! I have a byte array filled from a file uploaded. But, in another part of the code, I need to know this file type uploaded from the byte[] so I can render the correct content-type to browser! Thanks!! ...

ASP.NET MVC - does AntiForgeryToken prevent the user from changing posted form values?

I understand that the AntiForgeryToken feature in ASP.NET MVC does prevent cross-site attacks. However, does it prevent from changing form values before POST? For example, a malicious attacker may find out that the rating page always contains a hidden field contaning the rated entity ID and create POST requests to artificially rate al...

is it posible to upload directly to remote server using SFTP on ASP.net MVC

Hi! I am currently develope something using asp.net MVC, im still quite not experience with it so please help me out. I have a form for user to upload Video. The current ideal concept to upload to remote server is to Upload it to to the current server, then use FTP to push it to a remote server. For me, this is not quite fast since yo...

Having troubles loading related entities (Eager Load) with ObjectContext.CreateQuery (Entity Framework and Repositories)

Here's a bunch of things I tried... hopefully you can extrapolate from it what I'm trying to do and what I'm doing wrong. Okay so I'm having problems with loading related entities when using this DoQuery: public ObjectQuery<E> DoQuery(ISpecification<E> where) { return (ObjectQuery<E>)_ctx.CreateQuery<E>("[" + typeof(E).Nam...

How can I attach a custom membership provider in my ASP.NET MVC application?

How do I tie up my custom membership provider with my ASP.NET MVC [Authorize()] attribute? I've blasted through a number of tutorials for how to create a custom membership provider but all the information I've found about how to hook it up to an application seems to revolve around regular ASP.NET WebForms applications which seem to be a...

ASP MVC storing page states for later restoring

I have a fairly complex ASP MVC set of controls that set a data filter (account ID range, cost range, carrier, dates etc). This also creates a data table object with the standard result set type object. The user might wonder away from the page and then come back. I want to restore the previous filter control states and also pull the cur...

Cannot insert duplicate key.

I am getting this error ... Violation of PRIMARY KEY constraint 'PK_Members'. Cannot insert duplicate key in object 'dbo.Members'. The statement has been terminated. When I try to use the Membership and Role Providers in ASP.NET MVC. It happens when calling the GetUser method from inside the RoleProvider. var member = System....

Precompiling ASP.NET MVC on Mono with Web Deployment Project

I am trying to precompile and deploy my ASP.NET MVC application from Visual Studio 2008 to a server running Mono 2.4 using a Visual Studio 2008 Web Deployment Project. Whenever I go to the website, however, I get an error message: This is a marker file generated by the precompilation tool, and should not be deleted! Has anyone...

asp.net MVC - conditional compilation directly in aspx (site.master)?

Hi there, I seem to be having an issue with the conditional compilation tags directly en my site.master.. basically i have the following but it reports "Cannot resolve symbol DEBUG" in the compiler alhough i can run in DEBUG and RELEASE ... but the final output always prints whats in DEBUG weather i am in RELEASE or DEBUG... And as me...

Custom Security in ASP.NET MVC For Applications (Not mass market web sites)

I'm building a SaaS app and have some issues in dealing with authorization and ASP.NET MVC. I have a previous question and this is kind of taking a cue from comments there. I need to provide somewhat granular security (e.g. lots of permissions) for each user. I realize that any discretionary system can be modeled as a roles system by jus...

Some Fields Not Coming Through In ModelBinder

The following is the code for my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Actor actor) { try { actorRepository.Save(actor); return RedirectToAction("Index"); } catch { return View("Edit"); } } The view...

Where can I find a simple ASP.NET MVC (C#) tutorial(s)?

I am coming from a PHP background and I am familiar with OOP concepts, but I am moving away from PHP and trying out ASP.NET MVC using C#. Even without being forced to use web forms, this is a big jump for me coming from PHP. This is worsened by the fact that there are not very many tutorials out there on this subject in comparison to P...