Im writing a web app using C# with ASP.NET 4.5/Entity as a backend. With Angular.js handling
most of the front-end/database query stuff. ASP.NET 4.5 makes it really easy to connect to
our active directory using windows authentication.
However will I run into problems when I scrap all the razor templates, and replace it with regular HTML/CSS and angular scripts. All I really need the active directory stuff for is to create permission for who can pull what file from our database.
Im pretty new to web apps, so far ive like the entity framework alot, but if you guys know a more efficient way (better back end) to do this feel free to tell me.
My app basically needs to allow users to upload spreadsheets and videos, search for them, and only allow access to users that are in certain AD groups.
We solved this problem by using MVC to render the HTML templates. In your controller or directive set the templateUrl to an action which does whatever logic is necessary to render the template for that user. Also, be sure to check user permissions in your AJAX calls.
Figured it out. Made a new web api controller
then added this function
public string getUser()
{
return User.Identity.Name;
}
haha that was easy.
However if anyone sees any errors i may run into doing it this way. Please point em out
Related
I'm taking a summer development course and have been working on writing an API that will allow the user to log in to a personal, work, or school Microsoft.com account and do basic CRUD operations on the events in their calendar. Things like querying for all events within a date range or events that have a specified Open Extension property, etc.
Having finished that, I'm now working on writing a front end for it using ASP.net Core 1.1 MVC. The basic goal here is to list the results of the user's query with a few details, then allow the user to select an event to view all its details, edit it, or delete it. There would be a separate view to allow creation of new events. However, the authentication method I was using prior to switching from a basic console application to ASP.net Core 1.1 MVC (from the Microsoft Graph UWP Snippets located here) does not seem to work with ASP.net Core 1.1. Specifically, line 58 from the link above (AcquireTokenSilentAsync()).
I've done a good bit of digging before deciding to come and ask a question here, but I honestly feel like I'm getting nowhere/have been wasting time that I need to be spending on development. For reasons related to the course the professor is very hands-off, so asking him for assistance isn't an option.
How would one go about setting up an ASP.net Core 1.1 MVC app to allow access to the logged-in user's calendar? I've honestly not been able to find much, and since my API is currently very dependent on the token returned from the above Authentication method (it is used with both the HttpClient and GraphServiceClient used in my API) I'm going to need to figure something out soon.
UPDATE: I found a tutorial for using OpenIdConnect to log a user in to their Microsoft.com account in Asp.net MVC 6, however I'm not sure if there is a way to get at the authentication token that I need to use the Graph Client/HttpClient. Additionally, I haven't been able to find a similar tutorial for ASP.net Core 1.1 MVC. I'll keep digging and post anything I find here.
UPDATE 2: Wasn't having luck with that, have switched to attempting to use the OAuth 2.0 Authorization Code Grant Flow. Currently having a bit of trouble understanding how to get the authorization code to get the access token. If I set responseMode=query, do I actually have to query my application's redirect url (in this case localhost:xxxx/) that was created when I registered my app, or is the response automatically returned after the user logs in/consents to letting my app access their data?
UPDATE 3: I'm getting closer to having a functioning authentication process by following the steps in the link in Update 2. At this point I guess I'm just curious if my original method of authentication (almost identical to what is contained in the link in my original post) could have worked, or if I was going to find myself in this position no matter what.
I managed to use most of this sample repository: Microsoft Graph Webhooks Sample for ASP.NET Core to connect to Microsoft Graph API. It demonstrates using webhooks and MS Graph subscriptions, but it's how it gets the access token that is useful for us.
The relevant code snippet:
AuthenticationResult authResult = await authContext.AcquireTokenAsync(GraphResourceId,
new ClientCredential(AppId, AppSecret)); // For sample purposes only. Production apps should use a client certificate.
return authResult.AccessToken;
I have made a new project using the ASP.NET Web Application template in Visual Studio 2015. Then I selected MVC and Individual User Accounts to specify the template further. The solution I got is complete in that it offers me all the web pages you need for account management such as registering and logging in.
However, now I want to hook in a Xamarin.Forms mobile client to this account management scheme. I am making a native UI to register users, instead of redirecting them to a webpage or webview. I want to send user registration data, such as username and password, from this UI to the server so it will create an account. This means that I don't want to use the webpages offered by my MVC app, but rather send the registration data to the server and have it create an account, notfifying me of succes or failure.
I am anticipating that I would need to either use HTTP POSTs to login and registration endpoints in the AccountController or implement a public API. However, doing a post will return a webpage, and my client is not interested in a webpage.
I think one of the above should be possible to implement quite easily, but I am having a hard time searching for answers or methods, since I don't know how to phrase my problem properly, and with the abundance of guides on MVC, all my results are muddied.
Is my idea of this being possible flawed or have I missed a fundamental concept of MVC? What are the steps I should take in order to make this possible?
One misconception is that doing a POST will return a webpage. You can return any type of content from an MVC controller. But your account registration endpoints should be Web API controllers that return JSON. That JSON can be as simple as containing a boolean that indicates if the action was successful or not.
You do not need to use MVC at all. You can completely do away with the account controllers and views that the template created for you. Just copy the code that you need from the MVC controllers into your Web API methods.
You're right, this is quite easy to do.
I think, You can use ASP.NET Web API for doing this task. On server, you host your API for registering the users as well as logging into some client application.
Now, You need to consume this API in a client application. The client application could be a Console application, Windows application or a Web application. There are lots of tutorials about making an Web API on official ASP.NET site.
I have to build a Web-Application using ASP .NET MVC. It has to serve different customers, each customer accesses the Page via another domain. With this domain the Application is supposed to load the customer specific data. It also has to provide a login mechanism.
I'm fimiliar with JSF, there I would solve this problem via webfilters.
Does ASP.NET MVC provide something similar to webfilters or is there an even better solution so solve this problem?
I really wish there was a tutorial or an example that adresses this problem, but after hours of googeling I could not find anything. I'm probably searching with the wrong keywords, but I don't know how mechanisms like this are called.
There are several ways of doing this, for example you could use routing (Is it possible to make an ASP.NET MVC route based on a subdomain?) but I would simply go with getting the username from the URL.
var user = Request.Url.Host.Split('.')[0];
I’m trying to implement Google Analytics in my MVC website. First, I tried creating a GA account. Unfortunately, I’m developing locally on localhost which isn't a valid site URL, but I found a fix that will hopefully work here http://www.objectpartners.com/2011/05/26/setting-up-google-analytics-on-localhost/#comment-5960.
Then, I copied the generated JS tracking code and pasted it to a view. However, I found this article (http://analyticsimpact.com/2011/01/20/google-analytics-on-intranets-and-development-servers-fqdn/) about using NuGet package "GoogleAnalyticsTracker" which is supposed to let you track your site by using .NET framework. I followed these steps by adding the code to a controller, but the nothing is shown in the view.
I guess one solution would be creating a new GA account, copy the JS tracking code and paste it into /Views/Shared/_Layout.cshtml.
Anyone has experience implementing Google Analytics in a MVC4 application?
Thank you!
It's really as simple as:
Create a partial view named GoogleAnalytics
Copy & Paste the Analytics tracking JavaScript code from Google
Use #{ Html.RenderPartial("GoogleAnalytics"); } in a template which is used by all pages
Publish the site
Wait 24 hours for statistics to appear
This is my organised approach however you can put it in any location as long as the code is visible on every page you want to track.
I am trying to implement DotNetOpenid in my asp.net website. However, the more I try to read up on DotNetOpenid, the more confused I get. My initial goal is to allow user login process (similar to StackOverflow).
I attempted to get some help via this question dotnetopenid tutorial
but was unsuccessful (since I am not using MVC)
How can I get a tutorial that would help me accomplish that?
I would first start at the developers site
Coding Guidelines
Quick Start
Code Snippets
I have been posting my questions here Support Forum. Pretty helpful.
The ASP.NET OpenID web site (C#) project template isn't a tuturial, but it does create a functioning OpenID ASP.NET web site.
I just installed it and was able to get a site up and running. Here are a few gotchas that I ran into:
When you create a new project using the template, do not choose a deep path - this will create problems during database creation.
When you first run the application, you'll hit an exception - don't worry about it. When you get the YSOD, simply browse to the Setup.aspx page mentioned in the instructions.
If you don't have an OpenID, you'll need to get one. The initial page loaded after database creation has a 'Get OpenID' link if you need to get one. It's a simple process and only takes a few minutes.
Once you get through that, you'll have a working implementation of an OpenID web site.
You might also want to check out the DotNet OpenAuth ASP.NET Controls.
HTH
Edit
For anyone interested, there is also an ASP.NET MVC 2 OpenID web site (C#) template. I'm surprised #Andrew Arnott answered the other question and didn't mention these, since he is the author.