Connecting data two ways ASP.NET Core MVC - asp.net

I'm quite new to development and I have recently gotten into ASP.NET Core and I need help to figure out the following:
I need to connect my "characters" to my users upon creation via linking the username to the certain character, how would I go about to do this?
My guess is that upon the create method POST in my "CharactersController" I should be able to edit the "UserName" column for the characters upon creation to be linked to the user currently creating the character. But I am unsure how to do this.
I have tried to find relevant information in the documentation and in different guides but nothing seems to be what I'm looking for.
I appreciate any answers, thank you!

If you've already setup authentication / authorization properly, you should be able to use the method
User.FindFirst(ClaimTypes.NameIdentifier).Value
provided by the HttpContextAccessor library.

Related

How to develop a web browser using c# .net using installed.net libraries and without using the web browser control?

I have searched the internet for 2 days having found no answer to the below requirement. What i found most were GeckoFX and CefSharp which are external packages and not installed libraries. How can this be done?
I have been asked to do the following:
Use a suitable library function out of the set of libraries installed with the .NET platform. You must not use the C# WebBrowser class but perform the required HTTP-level communication directly from within your code. The code must clearly identify the HTTP-level client-server communication and must explicitly manage Home page, Favourite, History Lists and Tabs.
Optionally, you may add functionality to render a web page, but there must be an option to disable this functionality and to show only the raw HTML that has been retrieved.
Thanks
What have you attempted so far and what problem are you encountering?
Maybe read this first :)
Currently it sounds like you have been given an interview or homework task that you dont know how to solve. If so, then you should have some idea on where to start or you are in the wrong course or job interview. If you want help, then try to solve the question yourself and ask for help when you are stuck. Tell us what you have tried, show the code you currently have and let us know where you are stuck or what doesnt work as expected.
Where are you stuck? Fetching the webpage? Building the user interface?

How can make a query string like facebook.com/username?

I am building a website with asp.net. But I have an issue: I want to make user profile page link like in facebook.
For example,
"hostname.com/username" instead of "hostname.com/profile.aspx?something=something"
How can I achieve this?
Thank you for your time and valuable answers.
That feature called "URL Routing". If you are using MVC, then MVC Framework has That feature included. But if you are using Web Forms application, then You have to do this manual.
For Web Forms application, You can use Nuget Package Microsoft.AspNet.FriendlyUrls to make your application so that it generate url's what you want.
Refer http://www.devcurry.com/2013/05/friendly-urls-in-aspnet-web-forms.html
http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx (This is microsoft suggested)
This is typically done with a framework of some kind, but the concept it fairly simple --
If you're trying to do this quickly, you'll want to do your research on which one to use, but I'll explain the principle that makes it work -
In your server config (like an .htaccess) - you will rewrite the requests for *.aspx files go to a central index.aspx - this file then bootstraps your index however you want -
In your case, it would take the /username portion and query the database for a user with that username, fetch the associated data, and do whatever with it.
It's a relatively simple concept, and you could write something of your own device to bootstrap the request to your code, but you're probably better off looking for some (micro)framework that handles all that for you...
Good luck - !

New session per browser tab/window in ASP.NET MVC 3 app

I need to have a new session per browser window/tab. I am aware of the fact that ASP.NET assigns one session per process. I am also aware that browsers share this session between all open tabs/windows of the app. However, I need to come up with a way to create a new session for a new tab/window.
Cookieless session-state is not an option also. I already looked at that. I am looking to keep URL's clean.
I looked at the following solutions.
1) asp.net - session - multiple browser tabs - different sessions?. This solutions suggests using IsPostBack property, which is not available in MVC.
2) https://sites.google.com/site/sarittechworld/track-client-windows. This one looks very complex and I don't fully understand the javascript magic that is happening in it. I don't want to put in a solution that I don't understand. Also, I am not fully aware of any security holes that this solution may create.
Can someone point me in the right direction?
The only way to achieve this is to append the session id in the url which is what cookieless sessions are intended to do. Unfortunately you seem to have ruled out this possibility due to the ugly urls it produces.
I've created a NuGet package called ASP.NET MVC Conversational Session. Here you find more information: http://blog.micic.ch/net/asp-net-mvc-conversational-session
I released the first version yesterday. Have a look at the demo code or download the demo solution and let me know if there are things to improve. :)
EDIT: By default: The "identifier" is passed via URL when you use the appropriate extension method in the View. But you can add the identifier on your own. It gives you more flexiblity. (For example when you have links which are not generated via #Html.ActionLink.. etc.)

Is there any good way of SELF-updating running web application?

as stated - it needs to be a "self-update" similar like Wordpress... I haven't thought through because of my knowledge limits... (I haven't found any good answer from the web yet /asp.net c#)
anyone can give some help/ perhaps some code example would be better?
Thanks in advance!
I dont have the code, But i can tell you the general concept behind that.
Keep a public API/ Webservice which returns the latest version number of the site/ app.
In your website/ app, add a method which makes a call to this service to get the latest version number. compare it with what you have in your local application. If the one you received from the service is different than the one you have, That means there is a new version available. Then show a link to download the latest version.

ASP.NET/VB...users log on and see the own data only?

I'm attempting to make a system that stores employees details...name address etc.
I would like the users to be able to log on, see and change their own details only.
Is this possible is asp.net and if so how?
I'm really new at this so if you could keep answers as simple as possible.
Thanks
Here's a good starting point for your research...
Check out ASP.NET Membership. This is a good, out of the box, solution for storing basic "member" information (login/password/name/etc.). It will give you a good starting point for handling user authentication and building out ways for users to manager their info.
I usually use the SQL Membership Provider. Have a look at this link for good instructions on how to get it up and running.
You could look at the asp.net membership system, a walk-through can be found here - http://msdn.microsoft.com/en-us/library/879kf95c.aspx

Resources